package homework7_15;

import java.util.Arrays;

public class InsertionSort {
	public static void main(String[] avgs){
		int[] a={5,3,7,2,9,8,1,4};
		insertionSort(a);
		System.out.println(Arrays.toString(a));
	}
	public static void insertionSort(int[] a) {
	    int n = a.length;
	    for (int i = 1; i < n; i++) {
	        int key = a[i];
	        int j = i - 1;
	        while (j >= 0 && a[j] > key) {
	            a[j + 1] = a[j];
	            j--;
	        }
	        a[j + 1] = key;
	    }
	}

}
